﻿using System;
using System.Reflection;
using System.Configuration;
namespace ZX.HIS.DALFactory
{
	/// <summary>
    /// Abstract Factory pattern to create the DAL。
    /// 如果在这里创建对象报错，请检查web.config里是否修改了<add key="DAL" value="ZX.HIS.SQLServerDAL" />。
	/// </summary>
	public sealed class DataAccess 
	{
        private static readonly string AssemblyPath = ConfigurationManager.AppSettings["DAL"];        
		public DataAccess()
		{ }

        #region CreateObject 

		//不使用缓存
        private static object CreateObjectNoCache(string AssemblyPath,string classNamespace)
		{		
			try
			{
				object objType = Assembly.Load(AssemblyPath).CreateInstance(classNamespace);	
				return objType;
			}
            catch(System.Exception ex)
            {
                string str = ex.Message;// 记录错误日志
				return null;
			}			
			
        }
		//使用缓存
		private static object CreateObject(string AssemblyPath,string classNamespace)
		{			
			object objType = DataCache.GetCache(classNamespace);
			if (objType == null)
			{
				try
				{
					objType = Assembly.Load(AssemblyPath).CreateInstance(classNamespace);					
					DataCache.SetCache(classNamespace, objType);// 写入缓存
				}
				catch(System.Exception ex)
				{
					string str=ex.Message;// 记录错误日志
				}
			}
			return objType;
		}
        #endregion

        #region 泛型生成
        ///// <summary>
        ///// 创建数据层接口。
        ///// </summary>
        //public static t Create(string ClassName)
        //{

        //    string ClassNamespace = AssemblyPath +"."+ ClassName;
        //    object objType = CreateObject(AssemblyPath, ClassNamespace);
        //    return (t)objType;
        //}
        #endregion

   
		/// <summary>
		/// 创建AddPriOrthor数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IAddPriOrthor CreateAddPriOrthor()
		{
			string ClassNamespace = AssemblyPath +".AddPriOrthor";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IAddPriOrthor)objType;
		}
		/// <summary>
		/// 创建AuthorInfo数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IAuthorInfo CreateAuthorInfo()
		{
			string ClassNamespace = AssemblyPath +".AuthorInfo";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IAuthorInfo)objType;
		}


		/// <summary>
		/// 创建CaseInfo数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.ICaseInfo CreateCaseInfo()
		{
			string ClassNamespace = AssemblyPath +".CaseInfo";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.ICaseInfo)objType;
		}


		/// <summary>
		/// 创建ChargeHist数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IChargeHist CreateChargeHist()
		{

			string ClassNamespace = AssemblyPath +".ChargeHist";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IChargeHist)objType;
		}


		/// <summary>
		/// 创建DepartInfo数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IDepartInfo CreateDepartInfo()
		{

			string ClassNamespace = AssemblyPath +".DepartInfo";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IDepartInfo)objType;
		}


		/// <summary>
		/// 创建DiagnoInfo数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IDiagnoInfo CreateDiagnoInfo()
		{

			string ClassNamespace = AssemblyPath +".DiagnoInfo";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IDiagnoInfo)objType;
		}


		/// <summary>
		/// 创建DocAdvice数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IDocAdvice CreateDocAdvice()
		{

			string ClassNamespace = AssemblyPath +".DocAdvice";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IDocAdvice)objType;
		}


		/// <summary>
		/// 创建DrugFrequency数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IDrugFrequency CreateDrugFrequency()
		{

			string ClassNamespace = AssemblyPath +".DrugFrequency";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IDrugFrequency)objType;
		}


		/// <summary>
		/// 创建DrugInventory数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IDrugInventory CreateDrugInventory()
		{

			string ClassNamespace = AssemblyPath +".DrugInventory";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IDrugInventory)objType;
		}


		/// <summary>
		/// 创建DrugTypeInfo数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IDrugTypeInfo CreateDrugTypeInfo()
		{

			string ClassNamespace = AssemblyPath +".DrugTypeInfo";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IDrugTypeInfo)objType;
		}


		/// <summary>
		/// 创建DrugUsage数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IDrugUsage CreateDrugUsage()
		{

			string ClassNamespace = AssemblyPath +".DrugUsage";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IDrugUsage)objType;
		}


		/// <summary>
		/// 创建DrugUseInfo数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IDrugUseInfo CreateDrugUseInfo()
		{

			string ClassNamespace = AssemblyPath +".DrugUseInfo";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IDrugUseInfo)objType;
		}


		/// <summary>
		/// 创建DrugWareHouse数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IDrugWareHouse CreateDrugWareHouse()
		{

			string ClassNamespace = AssemblyPath +".DrugWareHouse";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IDrugWareHouse)objType;
		}


		/// <summary>
		/// 创建DrupInfo数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IDrupInfo CreateDrupInfo()
		{

			string ClassNamespace = AssemblyPath +".DrupInfo";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IDrupInfo)objType;
		}


		/// <summary>
		/// 创建Hospital数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IHospital CreateHospital()
		{

			string ClassNamespace = AssemblyPath +".Hospital";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IHospital)objType;
		}


		/// <summary>
		/// 创建LossHist数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.ILossHist CreateLossHist()
		{

			string ClassNamespace = AssemblyPath +".LossHist";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.ILossHist)objType;
		}


		/// <summary>
		/// 创建MeasuringUnit数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IMeasuringUnit CreateMeasuringUnit()
		{

			string ClassNamespace = AssemblyPath +".MeasuringUnit";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IMeasuringUnit)objType;
		}


		/// <summary>
		/// 创建MedicalItem数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IMedicalItem CreateMedicalItem()
		{

			string ClassNamespace = AssemblyPath +".MedicalItem";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IMedicalItem)objType;
		}


		/// <summary>
		/// 创建OpenDose数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IOpenDose CreateOpenDose()
		{

			string ClassNamespace = AssemblyPath +".OpenDose";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IOpenDose)objType;
		}


		/// <summary>
		/// 创建PatientInfo数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IPatientInfo CreatePatientInfo()
		{

			string ClassNamespace = AssemblyPath +".PatientInfo";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IPatientInfo)objType;
		}


		/// <summary>
		/// 创建Prescrit数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IPrescrit CreatePrescrit()
		{

			string ClassNamespace = AssemblyPath +".Prescrit";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IPrescrit)objType;
		}


		/// <summary>
		/// 创建PrescritDrug数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IPrescritDrug CreatePrescritDrug()
		{

			string ClassNamespace = AssemblyPath +".PrescritDrug";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IPrescritDrug)objType;
		}


		/// <summary>
		/// 创建Product数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IProduct CreateProduct()
		{

			string ClassNamespace = AssemblyPath +".Product";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IProduct)objType;
		}


		/// <summary>
		/// 创建RefundHist数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IRefundHist CreateRefundHist()
		{

			string ClassNamespace = AssemblyPath +".RefundHist";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IRefundHist)objType;
		}


		/// <summary>
		/// 创建RegistInfo数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IRegistInfo CreateRegistInfo()
		{

			string ClassNamespace = AssemblyPath +".RegistInfo";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IRegistInfo)objType;
		}


		/// <summary>
		/// 创建RegistType数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IRegistType CreateRegistType()
		{

			string ClassNamespace = AssemblyPath +".RegistType";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IRegistType)objType;
		}


		/// <summary>
		/// 创建RoleInfo数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IRoleInfo CreateRoleInfo()
		{

			string ClassNamespace = AssemblyPath +".RoleInfo";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IRoleInfo)objType;
		}


		/// <summary>
		/// 创建SaleHist数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.ISaleHist CreateSaleHist()
		{

			string ClassNamespace = AssemblyPath +".SaleHist";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.ISaleHist)objType;
		}


		/// <summary>
		/// 创建SeeDoctor数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.ISeeDoctor CreateSeeDoctor()
		{

			string ClassNamespace = AssemblyPath +".SeeDoctor";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.ISeeDoctor)objType;
		}


		/// <summary>
		/// 创建SeeDoctorMedicalItem数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.ISeeDoctorMedicalItem CreateSeeDoctorMedicalItem()
		{

			string ClassNamespace = AssemblyPath +".SeeDoctorMedicalItem";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.ISeeDoctorMedicalItem)objType;
		}


		/// <summary>
		/// 创建SeeDoctorPrescrit数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.ISeeDoctorPrescrit CreateSeeDoctorPrescrit()
		{

			string ClassNamespace = AssemblyPath +".SeeDoctorPrescrit";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.ISeeDoctorPrescrit)objType;
		}


		/// <summary>
		/// 创建StockHist数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IStockHist CreateStockHist()
		{

			string ClassNamespace = AssemblyPath +".StockHist";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IStockHist)objType;
		}


		/// <summary>
		/// 创建Supplier数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.ISupplier CreateSupplier()
		{

			string ClassNamespace = AssemblyPath +".Supplier";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.ISupplier)objType;
		}


		/// <summary>
		/// 创建UserInfo数据层接口。
		/// </summary>
		public static ZX.HIS.IDAL.IUserInfo CreateUserInfo()
		{

			string ClassNamespace = AssemblyPath +".UserInfo";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ZX.HIS.IDAL.IUserInfo)objType;
		}

}
}